﻿using LaunchAllaround.DesignPattern;
using LaunchAllaround.DesignPattern.MVC;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LaunchAllaround.Configuration
{
    public class ConfigurationModel : Model<ConfigurationModel>
    {

        public static readonly ConfigurationModel myself = new ConfigurationModel();

        public static readonly Language DefaultLanguage = Language.en;
        public static readonly Theme DefaultTheme = Theme.Dark;

        private ConfigurationModel()
        {
            Properties.Settings.Default.Colors = new System.Collections.ArrayList();

            this.language = ConfigurationModel.DefaultLanguage;

            this.theme = ConfigurationModel.DefaultTheme;
            this.playlistPath = "undefined";
            this.modelimpl = new ModelImpl<ConfigurationModel>();
            this.AddView(new ConfigurationUI());

            for (int i = 0; i < 16; i++)
            {
                Properties.Settings.Default.Colors.Add(16777215);
            }
        }

        private Language language;
        public Language Language { get { return this.language; } set { this.language = value; } }
        private Theme theme;
        public Theme Theme { get { return this.theme; } set { this.theme = value; } }
        private string playlistPath;
        public string PlaylistPath { get { return this.playlistPath; } set { this.playlistPath = value; } }

        // model functionalities
        private ModelImpl<ConfigurationModel> modelimpl;

        public void AddView(View<ConfigurationModel> v)
        {
            this.modelimpl.AddView(v);
        }

        public void ClearViews()
        {
            this.modelimpl.ClearViews();
        }

        public Container<View<ConfigurationModel>> GetViews()
        {
            return this.modelimpl.GetViews();
        }

        public void RefreshViews(RefreshEvent<ConfigurationModel> ev)
        {
            this.modelimpl.RefreshViews(ev);
        }

        public int[] GetCustomColors(){
            int[] customColors = new int[16];
            Properties.Settings.Default.Colors.CopyTo(customColors);
            return customColors;
        }

        public void SetCustomColors(int[] customColors)
        {
            System.Collections.ArrayList customColorsAL = new System.Collections.ArrayList();
            for (int i = 0; i < customColors.Length; i++ )
            {
                customColorsAL.Add(customColors[i]);
                System.Console.WriteLine(customColors[i]);
            }
            Properties.Settings.Default.Colors = customColorsAL;
            Properties.Settings.Default.Save();
        }

    }

    public enum Language {fr, en}
    public enum Theme { Dark, Light}
}
